package com.kedacom.demo.quartz2;

import java.util.Random;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// @Service("testJob")
public class TestJob extends Job {

	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	private TestService testService;

	@Override
	public void execute() {
		System.out.println("--test job");
		int n = new Random().nextInt(50);
		for (int i = 0; i < n; i++) {
			new Thread(runnable).start();
		}

		try {
			Thread.sleep(12000);
			testService.doWithoutSql();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		// testService.executeSomeBadSqlV1();
	}

	private Runnable runnable = new Runnable() {

		@Override
		public void run() {
			try {
				Thread.sleep(new Random().nextInt(5000));
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			testService.executeSomeSqlWithReadOnlyTransactional();
		}
	};

}
